﻿using System;
using System.Globalization;
using System.Windows.Forms;
using SoftwareConsulting.BI11.Studio.InternalServices;

namespace SoftwareConsulting.BI11.Studio.UI.ProjectExplorer.LogicalInferenceMechanism
{
    public partial class SituationsBindingForm : RestorableForm
    {
        bool ReallyClose = false; //окончательное закрытие формы
        MainForm _MainFormLink; //для связи с главной формой        

        /// <summary>
        /// Очищает все фразы
        /// </summary>
        public void ClearPhrases()
        {
            TranslationDataGrid.Rows.Clear();
        }

        /// <summary>
        /// Добавление новой фразы комментатора
        /// </summary>
        /// <param name="minute"></param>
        /// <param name="text"></param>
        public void AddEvent(double minute, string text)
        {
            TranslationDataGrid.Rows.Add();
            DataGridViewRow dr = TranslationDataGrid.Rows[TranslationDataGrid.Rows.Count - 1];
            dr.Cells[0].Value = Math.Truncate(minute).ToString(CultureInfo.CurrentCulture) + "'";
            dr.Cells[1].Value = text;
            TranslationDataGrid.Refresh();
        }
        
        /// <summary>
        /// Инициализация компонентов
        /// </summary>
        public SituationsBindingForm(MainForm mainForm)
        {
            _MainFormLink = mainForm;
            InitializeComponent();
        }

        /// <summary>
        /// Закрытие окна
        /// </summary>
        public void CloseAbsolutely()
        {
            ReallyClose = true;
            Close();
        }

        private void MatchTranslationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            _MainFormLink.ShowOrHideSituationsBindingForm(false);
            if (_MainFormLink.IsSituationsHierarchyFormVisible())
            {
                //РП отображено, значит надо б его развернуть на все окно                
                _MainFormLink.ShowOrHideSituationsHierarchyForm(false);
                _MainFormLink.ShowOrHideSituationsHierarchyForm(true);
                _MainFormLink.RestoreRulesContainerEditorIfNecessary();
            }
            e.Cancel = !ReallyClose;
        }

        private void MatchTranslationForm_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Bottom;
        }
    }
}
